package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.dto.ArticleStreamMessageDto;
import com.heima.article.service.IApArticleService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * 监听热门文章积分
 *
 * @Author : wuqiang
 * @date : 2022年10月21日
 */
@Component
public class HotArticleScoreListener {

    @Autowired
    private IApArticleService apArticleService;

    /**
     * 更新文章分数
     *
     * @param record 记录
     */
    @KafkaListener(topics = "hot_article_score_result_topic")
    public void updateHotArticleScore(ConsumerRecord<String, String> record) {
        String value = record.value();
        ArticleStreamMessageDto articleStreamMessage = JSON.parseObject(value, ArticleStreamMessageDto.class);
        apArticleService.updateHotArticleScore(articleStreamMessage);
    }

}
